﻿$(function () {
    createUploader();

    $("#records").ggrid({
        url: '/Files/GridLoad',
        dataType: 'json',
        columns: [
		    { display: 'Url', name: 'Url', width: 40, sortable: true, align: 'left' },
		    { display: 'Type', name: 'ContentType', width: 120, sortable: true, align: 'left' },
            { display: 'Size', name: 'Size', width: 180, sortable: true, align: 'left' },
            { display: 'Last Modified', name: 'LastModified', width: 120, sortable: true, align: 'left', formatFunction: formatDate }
		],
        actions: [
		    { idColumn: 'ID', image: '/Content/images/view-icon.gif', action: '/Files/View/{0}', showConfirm: false },
            { idColumn: 'ID', image: '/Content/images/download_icon.gif', action: '/Files/Download/{0}', showConfirm: false },
            { idColumn: 'ID', image: '/Content/images/pencil.png', action: '/Files/Create/{0}', showConfirm: false },
		    { idColumn: 'ID', image: '/Content/images/cross.png', action: '/Files/Delete/{0}', showConfirm: true }
		],
        defaultSort: "LastModified",
        defaultSortOrder: "desc",
        usePaging: true,
        pageSize: 10,
        width: 'auto',
        height: 'auto'
    });
});

function createUploader() {
    var uploader = new qq.FileUploader({
        element: document.getElementById('file-uploader'),
        action: '/Files/Upload',
        params: {},
        allowedExtensions: [],
        sizeLimit: 0,
        minSizeLimit: 0,
        onSubmit: function (id, fileName) { },
        onProgress: function (id, fileName, loaded, total) { },
        onComplete: function (id, fileName, responseJSON) {
            //location.href = "/Files?msg=1";
        },
        onCancel: function (id, fileName) { },
        messages: {},
        showMessage: function (message) { alert(message); },
        debug: true
    });
}